package com.beteng.su.betengsu.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class DateTimeUtils {
    private static SimpleDateFormat sdf = null;
    private String ip = null;
    public DateTimeUtils(){

    }

    public static String getIPTimeRand(){
        StringBuffer buf = new StringBuffer();
        buf.append(getTimeStamp());            //取得时间戳
        Random r = new Random();
        for(int i=0;i<3;i++){
            buf.append(r.nextInt(10));              //增加一个随机数
        }
        return buf.toString();
    }
    private String addZero(String str, int len){
        StringBuffer s = new StringBuffer();
        s.append(str);
        while(s.length()<len){
            s.insert(0,"0");
        }
        return s.toString();
    }
    public static String getDate(){
        sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        return sdf.format(new Date());
    }
    public static String getTimeStamp(){
       sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        return sdf.format(new Date());
    }

    public static String getSimpleStamp(){
        sdf = new SimpleDateFormat("yyyyMMdd");
        return sdf.format(new Date());
    }

    public static String getSimpleHour(){
        sdf = new SimpleDateFormat("HH");
        return sdf.format(new Date());
    }

    public static String getSimpleDate(){
       sdf = new SimpleDateFormat("MM-dd HH:mm");
        return sdf.format(new Date());
    }

    public static String getSimpleTime(){
       sdf = new SimpleDateFormat("HH:mm");
        return sdf.format(new Date());
    }

    public static String getDate(long stemp) {
        sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        return sdf.format(new Date(stemp));
    }

    public static String getDateWithFormat(String str, long stemp){
        sdf = new SimpleDateFormat(str);
        return sdf.format(new Date(stemp));
    }

    public static String getDateWithFormat(String str){
        sdf = new SimpleDateFormat(str);
        return sdf.format(new Date());
    }


}